package StudyCode.Component;

import javax.swing.*;

/**
 * @author lixiaoyao
 * @date 2018/11/22 0022、上午 8:21
 * @description 选择panel
 */
public class ButtonPanel extends JPanel {

	private ButtonGroup group;

	public ButtonPanel(String title, String... options) {
		this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), title));
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		this.group = new ButtonGroup();

		// make one radio button for each option
		for (String option : options) {
			JRadioButton radioButton = new JRadioButton(option);
			radioButton.setActionCommand(option);
			add(radioButton);
			group.add(radioButton);
			radioButton.setSelected(option.equals(options[0]));
		}

	}

	public String getSelection() {
		return this.group.getSelection().getActionCommand();
	}
}
